﻿using System;
using System.Linq;
using _5E.Infrastructure.Querying;
using Melee.Contract;
using Melee.DataContract.Extension;
using Melee.DataContract.Messaging;
using Melee.Models.Entity;
using Melee.Models.Repository;

namespace Melee.Service.Services
{
    public class CityService : ICityService
    {
        private ICityRepository m_cityRepository = null;

        public CityService(ICityRepository cityRepository)
        {
            m_cityRepository = cityRepository;
        }

        public GetCityDetailResponse GetDetailBy(GetCityDetailRequest request)
        {
            GetCityDetailResponse response = new GetCityDetailResponse();
            try
            {
                Query query = new Query();
                query.Add<City>(c => c.PlayerId, CriteriaOperator.Eq, request.LoginId);
                query.Add<City>(c => c.Id, CriteriaOperator.Eq, request.CityId);
                City city = m_cityRepository.FindBy(query).FirstOrDefault();
                if (null != city)
                    response.City = city.ConvertToPlayerCityView();
                else
                    response.Success = false;
            }
            catch (Exception ex)
            {
                response.Exception = ex;
                response.Success = false;
                response.Message = "获取城池明细失败!";
            }
            return response;
        }
    }
}
